package com.example.loggingservice.common;

import lombok.Data;

import java.io.Serializable;

@Data
public class R<T> implements Serializable {

    private static final int SUCCESS_CODE = 200;
    private static final int ERROR_CODE = 500;

    private int code;
    private String message;
    private T data;

    public static <T> R<T> success(T data) {
        R<T> r = new R<>();
        r.setCode(SUCCESS_CODE);
        r.setMessage("Success");
        r.setData(data);
        return r;
    }

    public static <T> R<T> success() {
        return success(null);
    }

    public static <T> R<T> error(String message) {
        R<T> r = new R<>();
        r.setCode(ERROR_CODE);
        r.setMessage(message);
        return r;
    }
} 